#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/10/20 下午 07:57
# @Author  : wasdzy
# @Site    : 
# @File    : Detail.py
# @Software: PyCharm
import requests

# position = []
# postion_dict = {
#     'positionName': position['positionName'],
#     'workYear': position['workYear'],
#     'salary': position['salary'],
#     'district': position['district'],
#     'companyFullName': position['companyFullName'],
# }
# position_id = position['positionId']
import sys
from bs4 import BeautifulSoup
import lxml

sysCode = sys.getfilesystemencoding()


def crawl_detail(id):
    url = 'https://www.lagou.com/jobs/%s.html' % id
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
        'Host': 'www.lagou.com',
        'Referer': 'https://www.lagou.com/jobs/list_python?labelWords=sug&fromSearch=true&suginput=p',
        # 'Upgrade-Insecure-Requests': '1',
    }
    req = requests.get(url, headers=headers)
    content = req.content.decode(sysCode)
    soup = BeautifulSoup(content, 'lxml')
    job_bt = soup.find('dd', attrs={'class': 'job_bt'})
    try:
        return job_bt.text
    except Exception as e:
        print('id = %s 爬取失败：%s' % (id, e))
#
# if __name__ == '__main__':
#     crawl_detail('5077367')
